<template name="basics">
	<view>
		<view class="cu-custom" :style="[{height:CustomBar + 'px'}]" style="background-color: #0081FF;">
			<view class="cu-bar fixed" :style="style">
				<view class="content" :style="[{top:StatusBar + 'px'}]" style="color: #FFFFFF;">
					首页
				</view>
				<view class="left-top">
					<text>{{city}}</text>
					<!-- <image src="../../static/u64.png" mode=""></image> -->
					<text v-if="show" style="margin-left: 12rpx;">{{now.type}}</text>
					<text v-if="show">{{now.low | temperature}}-{{now.high | temperature}}</text>
				</view>
				<view class="right absoult" @click="goMessage">
					<image style="width:40rpx;height:40rpx;" src="../../static/u67.png" mode=""></image>
					<view class="inner" v-show="message>0">
						{{message}}
					</view>
				</view>
			</view>
		</view>
		<view>
				<!-- 定图换掉 -->
		<!-- 	<view class="logoimg">
				<image src="../../static/componentBg.png" mode=""></image>
			</view> -->
			<view style="background-color:#fff;margin-bottom:40rpx;padding: 20rpx 0;">
				<view class="service">
					服务
				</view>
				<view class="xian">
				</view>
				<view class="content-top">
					<view class="top-item" @click="godetail(item)" v-for="(item,index) in  elements" :key="index">
						<view class="left">
							<image class="image" :src="'../../static/img/basics/'+item.img" mode=""></image>
							<view class="tpimg-content">
								{{item.name}}
							</view>
						</view>
					</view>
				</view>
			</view>
			<!-- <view style="background-color:#fff;margin-bottom:40rpx;padding: 20rpx 0;">
				<view class="service">
					安全
				</view>
				<view class="xian">
				</view>
				<view class="content-top">
					<view class="top-item" @click="godetailbottom(item)" v-for="(item,index) in  botelements" :key="index">
						<view class="left">
							<image class="image" :src="'../../static/img/basics/'+item.img" mode=""></image>
							<view class="tpimg-content">
								{{item.name}}
							</view>
						</view>
						<!<view class="rightborn">
								<image class="horn" src="../../static/img/u33.png" mode=""></image>
						</view> -->
				<!-- 	</view>
				</view>
			</view> --> 
		</view>
	</view>
</template>

<script>
	export default {
		name: "basics",
		data() {
			return {
				show:false,//天气是否展示
				message: '', //消息数量
				StatusBar: this.StatusBar, //顶部栏的配置
				CustomBar: this.CustomBar,
				elements: [{
						img: 'u81.png',
						name: '照护服务',
						url: '/pages/basics/services/index'
					},
					{
						img: 'u88.png',
						name: '日常查房',
						url: '/pages/basics/daily/index'
					},
					{
						img: 'u87.png',
						name: '区域服务',
						url: '/pages/basics/regional/index'
					},
					// {
					// 	img: 'u82.png',
					// 	name: '服务统计'
					// },
					{
						img: 'u84.png',
						name: '外出登记',
						url: '/pages/basics/goout/index'
					},
					// {
					// 	img: 'u85.png',
					// 	name: '协助服药'
					// },
					// {
					// 	img: 'u86.png',
					// 	name: '协助点餐'
					// },
					{
						img: 'u83.png',
						name: '长者档案',
						url: '/pages/basics/elder/index'
					}
				],
				// 元素
				// botelements: [{
				// 		img: 'u100.png',
				// 		name: '消防巡查',
				// 		url: '/pages/basics/fire/index'
				// 	},
				// 	{
				// 		img: 'u103.png',
				// 		name: '防火巡查',
				// 		url: '/pages/basics/fireproof/index'
				// 	},
				// 	{
				// 		img: 'u106.png',
				// 		name: '随手拍',
				// 		url: '/pages/basics/clap/index'
				// 	}
				// ],//下面的元素
				city:'',//当前城市
				now:{} //当前日期的天气
			}
		},
		computed: {
			style() {
				var StatusBar = this.StatusBar;
				var CustomBar = this.CustomBar;
				var style = `height:${CustomBar}px;padding-top:${StatusBar}px;`;
				return style
			}
		},
		onReady() {},
		onTabItemTap(){
			if(this.$store.state.state&&this.$store.state.isphone){
				getApp().globalData.TTSSpeaker.stop();
				getApp().globalData.TTSSpeaker.speak(`首页`,1);
			}	
		},
		onShow() {
			// 判断浏览器
			
			const that = this;
			uni.$on("NFC_READ", function(msg) {
				that.readCard(msg.rfid);
			});
		},
		onLoad() {
			if(navigator){
			}else{
				 console.log('99999999')
				this.getLocation();
			}
			this.getHasReadMessageFlag();
		},
		onUnload() {
			// 移除监听事件
		},
		onHide() {
			uni.$off("NFC_READ");
		},
		methods: {
			// 获取经纬度
			getLocation(){
				const _that = this
				uni.getLocation({
				    type: 'wgs84',
				    success: function (res) {
				        console.log('当前位置的经度：' + res.longitude);
				        console.log('当前位置的纬度：' + res.latitude);
						_that.getCityName(res.longitude,res.latitude)
				    }
				});
			},
			// 城市
			// care-service/service/getCityName?longitude=31.225696429417988&latitude=121.49884033193993
			getCityName(longitude,latitude){
				let param = {
					longitude:latitude,
					latitude:longitude
				}
				 console.log(param,'param')
				this.$http('/care-service/service/getCityName','get',param).then(res=>{
					 console.log(res,'citycity')
					if(res.data.code==200){
						this.city = res.data.data
							uni.request({
								url: 'http://wthrcdn.etouch.cn/weather_mini?city='+this.city, //仅为示例，并非真实接口地址。
								success: (res) => {
									this.now = res.data.data.forecast[0]
									console.log(this.now,'6666666666');
									this.show = true
								}
							});
					}
				});
			},
			//；消息goMessage#/pages/my/message-center/message-center
			goMessage() {
				uni.navigateTo({
					url: '/pages/my/message-center/message-center'
				})
				if(this.$store.state.state&&this.$store.state.isphone){
					getApp().globalData.TTSSpeaker.stop();
					getApp().globalData.TTSSpeaker.speak(`消息中心`,1);
				}	
			},
			// 顶部是否有消息
			getHasReadMessageFlag() {
				let param = {}
				param.teamId = uni.getStorageSync('teamId')
				this.$http('/care-service/myMessage/getHasReadMessageFlag', 'get', param).then(res => {
					if (res.data.code == 200) {
						this.message = res.data.data
					}
				});
			},
			readCard(id) {
				console.log(9999)
				this.$http('/implement-service/implement/getByRfidCardIdForService', 'get', {
					rfidCardId: id
				}).then(res => {
					console.log(res, 9999)
					if (res.data.code == 200) {
						const data = res.data.data;
						console.log(data)
						if (data == undefined) {

						}
						if (data.serviceTarget == 0) {
							let param = {
								id: data.serviceObject.id
							}
							this.$http('/care-service/oldBaseDetail/getOldBaseInfo', 'get', param).then(res => {
								 console.log(res,'resresresres')
								if (!res.data.data.outStatus) {
									if (this.$store.state.state && this.$store.state.isphone) {
										getApp().globalData.TTSSpeaker.stop();
										getApp().globalData.TTSSpeaker.speak('长者已经外出', 1);
									}
									uni.showToast({
										title:'长者已经外出',
										icon:'none'
									})
								} else {
									if (this.$store.state.state && this.$store.state.isphone) {
										getApp().globalData.TTSSpeaker.stop();
										getApp().globalData.TTSSpeaker.speak('进入芯片对应长者详情页面', 1);
									}
									uni.navigateTo({
										url: 'services/detail?oldBaseId=' + res.data.data.oldBaseId
									})
								}
							});
						}
						if (data.serviceTarget == 1) {
							if (this.$store.state.state && this.$store.state.isphone) {
								getApp().globalData.TTSSpeaker.stop();
								getApp().globalData.TTSSpeaker.speak('进入芯片对应房间详情页面', 1);
							}
							uni.navigateTo({
								url: 'daily/detail?roomName=' + data.serviceObject.name + '&roomId=' + data.serviceObject.id
							})
						}
						if (data.serviceTarget == 2) {
							if (this.$store.state.state && this.$store.state.isphone) {
								getApp().globalData.TTSSpeaker.stop();
								getApp().globalData.TTSSpeaker.speak('进入芯片对应服务点详情页面', 1);
							}
							uni.navigateTo({
								url: 'regional/detail?id=' + data.serviceObject.id
							})
						}
					} else if (res.data.code == 2000) {
						if (this.$store.state.state && this.$store.state.isphone) {
							getApp().globalData.TTSSpeaker.stop();
							getApp().globalData.TTSSpeaker.speak(res.data.message, 1);
						}
					}
				})
			},
			// 跳转到详情页
			godetail(item) {
					const that = this;
					//有url
					if(item.url){
						if (this.$store.state.state && this.$store.state.isphone) {
							getApp().globalData.TTSSpeaker.stop();
							getApp().globalData.TTSSpeaker.speak(item.name, 1);
							const times = item.name.length*200;
								uni.navigateTo({
									url: item.url
								})
						}else{
							uni.navigateTo({
								url: item.url
							})
						}
					}else{
						if(this.$store.state.state&&this.$store.state.isphone){
							getApp().globalData.TTSSpeaker.stop();
							getApp().globalData.TTSSpeaker.speak(`${item.name}正在开发中`,1);
						}
						uni.showToast({
							title: '正在开发中',
							icon:'none'
						})
					}
				},
				godetailbottom(item){
					if(this.$store.state.state&&this.$store.state.isphone){
						getApp().globalData.TTSSpeaker.stop();
						getApp().globalData.TTSSpeaker.speak(`${item.name}正在开发中`,1);
					}
					uni.showToast({
						title: '正在开发中',
						icon:'none'
					})
				}
			},
			// 获取城市 js代码
	}
</script>
<style lang="scss" scoped>
.absoult{
	position: relative;
	padding-right:30rpx;
	.inner{
		background-color: red;
		position: absolute;
		top: 8rpx;
		right:-2rpx;
		transform: translate(-50%,-50%);
		border-radius:50%;
		color: #FFFFFF;
		width:26rpx;
		height:26rpx;
		font-size: 24rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}
}

	.left-top {
		display: flex;
		align-items: center;
		padding-left: 30rpx;
		color: #FFFFFF;

		image {
			width: 40rpx;
			height: 40rpx;
			margin: 0 8rpx;
		}
	}

	.page {
		height: 100vh;
	}

	page {
		background-color: #F2F2F2;
	}

	.content-top {
		display: flex;
		justify-content: flex-start;
		align-content: center;
		flex-wrap: wrap;

		.top-item {
			margin-top: 40rpx;
			width: 25%;
			display: flex;
			justify-content: center;

			.left {
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
			}

			.right {}
		}
	}

	.image {
		width: 80rpx;
		height: 80rpx;
	}

	.logoimg {
		display: flex;
		justify-content: center;
		align-items: center;
		background-color: #CCCCCC;

		image {
			width: 90%;
			height: 200rpx;
			margin: 30rpx 0;
		}
	}

	.tpimg-content {
		margin-top: 20rpx;
	}

	.service {
		border-left: 1rpx solid #0057A8;
		margin: 0 30rpx 20rpx;
		display: flex;
		align-items: center;
		padding-left: 10rpx;
		color: #0057A8;
	}

	.xian {
		margin: 0 30rpx;
		height: 0.5rpx;
		background-color: #CCCCCC;
		box-sizing: border-box;
	}
</style>
